import Vue from "vue";
import Vuex from "vuex";
import { reqCategoryList,reqBannerList } from "@/api";

Vue.use(Vuex);
const state = {
  categoryList: [],
  bannerList:[],
};
const getters = {};
const actions = {
  // 在actions里面调用接口
  async getCategoryList(homeStore) {
    const result = await reqCategoryList();
    if (result.code === 200) {
      homeStore.commit("GETCATEGORYLIST", result.data);
    }
  },
  async getBannerList({commit}) {
    const result = await reqBannerList();
    // console.log(result,'res');
    if (result.code === 200) {
      commit("GETBANNERLIST", result.data);
    }
  },
};
const mutations = {
  GETCATEGORYLIST(state, value) {
    state.categoryList = value;
    // console.log(state, "state");
  },
  GETBANNERLIST(state, value) {
    state.bannerList = value;
    // console.log(state.bannerList,'banner');
  },
};
export default {
  state,
  mutations,
  getters,
  actions,
};
